.class final Lcom/burstly/lib/service/ServerConfigurationService$2;
.super Ljava/lang/Object;
.source "ServerConfigurationService.java"

# interfaces
.implements Ljava/lang/Runnable;


# annotations
.annotation system Ldalvik/annotation/EnclosingMethod;
    value = Lcom/burstly/lib/service/ServerConfigurationService;->createLoadCfgRunnable(Landroid/content/Context;Ljava/lang/String;)Ljava/lang/Runnable;
.end annotation

.annotation system Ldalvik/annotation/InnerClass;
    accessFlags = 0x8
    name = null
.end annotation


# instance fields
.field private final mFileHandler:Lcom/burstly/lib/persistance/ObjectSaveLoadHandler;
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "Lcom/burstly/lib/persistance/ObjectSaveLoadHandler",
            "<",
            "Ljava/util/HashMap",
            "<",
            "Ljava/lang/String;",
            "Ljava/lang/Object;",
            ">;>;"
        }
    .end annotation
.end field

.field final synthetic val$context:Landroid/content/Context;

.field final synthetic val$publisherId:Ljava/lang/String;


# direct methods
.method constructor <init>(Ljava/lang/String;Landroid/content/Context;)V
    .locals 1
    .parameter
    .parameter

    .prologue
    .line 296
    iput-object p1, p0, Lcom/burstly/lib/service/ServerConfigurationService$2;->val$publisherId:Ljava/lang/String;

    iput-object p2, p0, Lcom/burstly/lib/service/ServerConfigurationService$2;->val$context:Landroid/content/Context;

    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 300
    sget-object v0, Lcom/burstly/lib/service/ServerConfigurationService;->sFileHandler:Lcom/burstly/lib/persistance/ObjectSaveLoadHandler;

    iput-object v0, p0, Lcom/burstly/lib/service/ServerConfigurationService$2;->mFileHandler:Lcom/burstly/lib/persistance/ObjectSaveLoadHandler;

    return-void
.end method


# virtual methods
.method public run()V
    .locals 13

    .prologue
    .line 305
    :try_start_0
    invoke-static {}, Ljava/lang/Thread;->currentThread()Ljava/lang/Thread;

    move-result-object v1

    .line 307
    .local v1, currentThread:Ljava/lang/Thread;
    sget-object v8, Lcom/burstly/lib/service/ServerConfigurationService;->sTestConfiguration:Ljava/lang/String;

    if-nez v8, :cond_2

    .line 308
    invoke-virtual {v1}, Ljava/lang/Thread;->isInterrupted()Z

    move-result v8

    if-eqz v8, :cond_1

    .line 309
    sget-object v8, Lcom/burstly/lib/service/ServerConfigurationService;->LOG:Lcom/burstly/lib/util/LoggerExt;

    sget-object v9, Lcom/burstly/lib/service/ServerConfigurationService;->TAG:Ljava/lang/String;

    const-string v10, "Cancel configuration task"

    const/4 v11, 0x0

    new-array v11, v11, [Ljava/lang/Object;

    invoke-virtual {v8, v9, v10, v11}, Lcom/burstly/lib/util/LoggerExt;->logDebug(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    .line 349
    .end local v1           #currentThread:Ljava/lang/Thread;
    :cond_0
    :goto_0
    return-void

    .line 313
    .restart local v1       #currentThread:Ljava/lang/Thread;
    :cond_1
    new-instance v4, Lorg/apache/http/HttpHost;

    invoke-static {}, Lcom/burstly/lib/constants/UriConstants;->getInstance()Lcom/burstly/lib/constants/UriConstants;

    move-result-object v8

    invoke-virtual {v8}, Lcom/burstly/lib/constants/UriConstants;->getPrimaryHost()Ljava/lang/String;

    move-result-object v8

    invoke-direct {v4, v8}, Lorg/apache/http/HttpHost;-><init>(Ljava/lang/String;)V

    .line 314
    .local v4, host:Lorg/apache/http/HttpHost;
    new-instance v2, Lcom/burstly/lib/service/ServerRequestBean;

    invoke-direct {v2}, Lcom/burstly/lib/service/ServerRequestBean;-><init>()V

    .line 315
    .local v2, data:Lcom/burstly/lib/service/ServerRequestBean;
    iget-object v8, p0, Lcom/burstly/lib/service/ServerConfigurationService$2;->val$publisherId:Ljava/lang/String;

    invoke-virtual {v2, v8}, Lcom/burstly/lib/service/ServerRequestBean;->setPublisher(Ljava/lang/String;)V

    .line 316
    iget-object v8, p0, Lcom/burstly/lib/service/ServerConfigurationService$2;->val$context:Landroid/content/Context;

    invoke-static {v8, v2}, Lcom/burstly/lib/util/Utils;->configureServerRequestBean(Landroid/content/Context;Lcom/burstly/lib/service/ServerRequestBean;)V

    .line 317
    invoke-static {v2}, Lcom/burstly/lib/util/Utils;->toJson(Ljava/lang/Object;)Ljava/lang/String;

    move-result-object v3

    .line 318
    .local v3, dataToPost:Ljava/lang/String;
    sget-object v8, Lcom/burstly/lib/service/ServerConfigurationService;->LOG:Lcom/burstly/lib/util/LoggerExt;

    sget-object v9, Lcom/burstly/lib/service/ServerConfigurationService;->TAG:Ljava/lang/String;

    const-string v10, "Data to post: {0}"

    const/4 v11, 0x1

    new-array v11, v11, [Ljava/lang/Object;

    const/4 v12, 0x0

    aput-object v3, v11, v12

    invoke-virtual {v8, v9, v10, v11}, Lcom/burstly/lib/util/LoggerExt;->logDebug(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    .line 320
    new-instance v5, Lorg/apache/http/client/methods/HttpPost;

    sget-object v8, Lcom/burstly/lib/constants/UriConstants;->CONFIGURATION_URI:Ljava/lang/String;

    invoke-direct {v5, v8}, Lorg/apache/http/client/methods/HttpPost;-><init>(Ljava/lang/String;)V

    .line 321
    .local v5, post:Lorg/apache/http/client/methods/HttpPost;
    new-instance v8, Lorg/apache/http/entity/StringEntity;

    const-string v9, "UTF-8"

    invoke-direct {v8, v3, v9}, Lorg/apache/http/entity/StringEntity;-><init>(Ljava/lang/String;Ljava/lang/String;)V

    invoke-virtual {v5, v8}, Lorg/apache/http/client/methods/HttpPost;->setEntity(Lorg/apache/http/HttpEntity;)V

    .line 322
    invoke-static {v4, v5}, Lcom/burstly/lib/util/Utils;->makeRequest(Lorg/apache/http/HttpHost;Lorg/apache/http/client/methods/HttpRequestBase;)Lorg/apache/http/HttpResponse;

    move-result-object v7

    .line 323
    .local v7, response:Lorg/apache/http/HttpResponse;
    invoke-interface {v7}, Lorg/apache/http/HttpResponse;->getEntity()Lorg/apache/http/HttpEntity;

    move-result-object v8

    invoke-static {v8}, Lorg/apache/http/util/EntityUtils;->toString(Lorg/apache/http/HttpEntity;)Ljava/lang/String;

    move-result-object v0

    .line 325
    .local v0, configuration:Ljava/lang/String;
    sget-object v8, Lcom/burstly/lib/service/ServerConfigurationService;->LOG:Lcom/burstly/lib/util/LoggerExt;

    sget-object v9, Lcom/burstly/lib/service/ServerConfigurationService;->TAG:Ljava/lang/String;

    const-string v10, "Recieved configuration {0} from server."

    const/4 v11, 0x1

    new-array v11, v11, [Ljava/lang/Object;

    const/4 v12, 0x0

    aput-object v0, v11, v12

    invoke-virtual {v8, v9, v10, v11}, Lcom/burstly/lib/util/LoggerExt;->logDebug(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    .line 330
    .end local v2           #data:Lcom/burstly/lib/service/ServerRequestBean;
    .end local v3           #dataToPost:Ljava/lang/String;
    .end local v4           #host:Lorg/apache/http/HttpHost;
    .end local v5           #post:Lorg/apache/http/client/methods/HttpPost;
    .end local v7           #response:Lorg/apache/http/HttpResponse;
    :goto_1
    invoke-virtual {v1}, Ljava/lang/Thread;->isInterrupted()Z

    move-result v8

    if-nez v8, :cond_0

    .line 333
    const-string v8, ""

    invoke-virtual {v8, v0}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v8

    if-nez v8, :cond_0

    .line 335
    sget-object v8, Lcom/burstly/lib/service/ServerConfigurationService;->CONFIGURATION_DATA:Ljava/util/HashMap;

    invoke-virtual {v8}, Ljava/util/HashMap;->clear()V

    .line 336
    sget-object v8, Lcom/burstly/lib/service/ServerConfigurationService;->CONFIGURATION_DATA:Ljava/util/HashMap;

    invoke-static {v0}, Lcom/burstly/lib/util/Utils;->fromJson(Ljava/lang/String;)Lcom/burstly/lib/network/ResponseObject;

    move-result-object v9

    invoke-virtual {v8, v9}, Ljava/util/HashMap;->putAll(Ljava/util/Map;)V

    .line 337
    iget-object v8, p0, Lcom/burstly/lib/service/ServerConfigurationService$2;->mFileHandler:Lcom/burstly/lib/persistance/ObjectSaveLoadHandler;

    sget-object v9, Lcom/burstly/lib/service/ServerConfigurationService;->CONFIGURATION_DATA:Ljava/util/HashMap;

    invoke-virtual {v8, v9}, Lcom/burstly/lib/persistance/ObjectSaveLoadHandler;->save(Ljava/io/Serializable;)V

    .line 339
    invoke-static {}, Lcom/burstly/lib/service/ServerConfigurationService;->getRecipientsSnapshot()Ljava/util/Set;

    move-result-object v8

    invoke-interface {v8}, Ljava/util/Set;->iterator()Ljava/util/Iterator;

    move-result-object v6

    .line 340
    .local v6, recIter:Ljava/util/Iterator;,"Ljava/util/Iterator<Lcom/burstly/lib/service/ServerConfigurationService$ConfigurationTaskWrapper;>;"
    :goto_2
    invoke-interface {v6}, Ljava/util/Iterator;->hasNext()Z

    move-result v8

    if-eqz v8, :cond_0

    .line 341
    invoke-interface {v6}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v8

    check-cast v8, Lcom/burstly/lib/service/ServerConfigurationService$IServerConfigurable;

    #calls: Lcom/burstly/lib/service/ServerConfigurationService;->safeApplyConfiguration(Lcom/burstly/lib/service/ServerConfigurationService$IServerConfigurable;)V
    invoke-static {v8}, Lcom/burstly/lib/service/ServerConfigurationService;->access$000(Lcom/burstly/lib/service/ServerConfigurationService$IServerConfigurable;)V

    goto :goto_2

    .line 346
    .end local v0           #configuration:Ljava/lang/String;
    .end local v1           #currentThread:Ljava/lang/Thread;
    .end local v6           #recIter:Ljava/util/Iterator;,"Ljava/util/Iterator<Lcom/burstly/lib/service/ServerConfigurationService$ConfigurationTaskWrapper;>;"
    :catch_0
    move-exception v8

    goto/16 :goto_0

    .line 327
    .restart local v1       #currentThread:Ljava/lang/Thread;
    :cond_2
    sget-object v0, Lcom/burstly/lib/service/ServerConfigurationService;->sTestConfiguration:Ljava/lang/String;

    .line 328
    .restart local v0       #configuration:Ljava/lang/String;
    sget-object v8, Lcom/burstly/lib/service/ServerConfigurationService;->LOG:Lcom/burstly/lib/util/LoggerExt;

    sget-object v9, Lcom/burstly/lib/service/ServerConfigurationService;->TAG:Ljava/lang/String;

    const-string v10, "Test configuration {0} applied."

    const/4 v11, 0x1

    new-array v11, v11, [Ljava/lang/Object;

    const/4 v12, 0x0

    aput-object v0, v11, v12

    invoke-virtual {v8, v9, v10, v11}, Lcom/burstly/lib/util/LoggerExt;->logDebug(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    goto :goto_1
.end method
